import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login')
  },
  {
    path: '/farmland',
    component: Layout,
    meta: { hidden: false, title: '田块管理' },
    children: [
      {
        path: 'list',
        component: () => import('@/views/farmland'),
        meta: { hidden: false, title: '田块管理' }
      },
      {
        path: 'add',
        component: () => import('@/views/farmland-add/canvasMap/index.vue'),
        meta: { hidden: false, title: '新增田块' }
      },
      {
        path: 'add2',
        hidden: true,
        component: () => import('@/views/farmland/add'),
        meta: { hidden: false, title: '编辑田块' }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/farmland-detail'),
        hidden: true,
        meta: { hidden: false, title: '田块详情' }
      },
      {
        path: 'edit/:id',
        hidden: true,
        component: () => import('@/views/farmland-edit/canvasMap'),
        meta: { hidden: false, title: '编辑田块' }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user',
    meta: { hidden: false },
    children: [
      {
        path: '/user',
        component: () => import('@/views/user'),
        meta: { hidden: false, title: '人员管理' }
      }
    ]
  },
  {
    path: '/screen',
    component: Layout,
    redirect: '/screen',
    meta: { hidden: false },
    children: [
      {
        path: '/screen',
        component: () => import('@/views/screen'),
        meta: { hidden: false, title: '大屏数据管理' }
      }
    ]
  },
  {
    path: '/internet',
    component: Layout,
    redirect: '/internet',
    meta: { hidden: false },
    children: [
      {
        path: '/internet',
        component: () => import('@/views/internet'),
        meta: { hidden: false, title: '物联网设备管理' }
      }
    ]
  },
  {
    path: '/log',
    component: Layout,
    redirect: '/log',
    meta: { hidden: false },
    children: [
      {
        path: '/log',
        name: 'log',
        component: () => import('@/views/log'),
        meta: { hidden: false, title: '日志管理' }
      }
    ]
  },
  {
    path: '/base-data',
    component: Layout,
    redirect: '/log',
    meta: { hidden: false },
    children: [
      {
        path: '/base-data',
        name: 'base-data',
        component: () => import('@/views/base-data'),
        meta: { hidden: false, title: '基础数据管理' }
      }
    ]
  },
  {
    path: '/brand',
    component: Layout,
    redirect: '/brand/index',
    meta: { hidden: false },
    children: [
      {
        path: 'index',
        name: 'brand',
        component: () => import('@/views/brand'),
        meta: { hidden: false, title: '品牌管理' }
      }
    ]
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
